package com.chenfan.process.service.impl;

import com.chenfan.notify.dto.NotifyDTO;
import com.chenfan.process.entity.po.ApprovalPo;
import com.chenfan.process.entity.po.ApprovalTemplatePo;
import com.chenfan.process.entity.po.ProcessInstanceApprovePo;
import com.chenfan.process.entity.po.TemplateConfigPo;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author K
 * @date 2023/3/21 4:02 PM
 */
public class NotifyDomainService {

    public static List<NotifyDTO> notifyDTO (
            ApprovalPo approvalPo,
            TemplateConfigPo templateConfigPo,
            ApprovalTemplatePo approvalTemplatePo,
            List<ProcessInstanceApprovePo> approvePoList) {

        return approvePoList.stream().map(e -> {
            NotifyDTO notifyDTO = NotifyDTO.ofDefault();
            notifyDTO.setApprovalId(e.getApprovalId());
            notifyDTO.setUserId(e.getUserId());
            notifyDTO.setUserName(e.getUserName());

            notifyDTO.setApprovalCode(approvalTemplatePo.getCode());
            // TODO 后续优化
            notifyDTO.setProjectName(approvalPo.getServiceName());
            notifyDTO.setMessageType(Long.valueOf(approvalTemplatePo.getCode()));
            notifyDTO.setMessageTypeValue(approvalTemplatePo.getTitle());
            notifyDTO.setCreateBy(approvalPo.getCreateBy());
            notifyDTO.setCreateName(approvalPo.getCreateName());
            notifyDTO.setApprovalCreateName(approvalPo.getCreateName());
            notifyDTO.setApprovalTime(approvalPo.getCreateTime());
            notifyDTO.setBusinessId(approvalPo.getBusinessId());
            notifyDTO.setBusinessCode(approvalPo.getBusinessCode());
            notifyDTO.setJumpUrlType(templateConfigPo.getJumpUrlType());
            notifyDTO.setMessageUrl(templateConfigPo.getMessageUrl());
            // TODO 后续使用到在优化
//            notifyDTO.setBelongSystem(approvalTemplatePo.getBelongSystem());
            return notifyDTO;
        }).collect(Collectors.toList());
    }
}
